package automation;

import java.util.Scanner;
import java.lang.NumberFormatException;

public class CO2Sensor implements ISensor {

    Central central;

    @Override
    public void start() {
        Scanner scanner = new Scanner(System.in);
        String line;
        while (!(line = scanner.nextLine()).equals("exit")) {
            try {
                central.receive(Integer.valueOf(line), this);
            } catch(NumberFormatException e) {
                System.out.println("input number hoe");
            }
        }
    }

    @Override
    public void register(Central central) {
        this.central = central;
    }

    @Override
    public boolean shouldBeOpen(int ppm, boolean opened) {
        if (ppm < 800 && opened) {
            return false;
        }

        if (ppm > 1000 && !opened) {
            return true;
        }

        return opened;
    }

}